package de.jmda.gen.java.impl;

import java.util.LinkedList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.AnnotationStatementsGenerator;
import de.jmda.gen.java.ParameterGenerator;
import de.jmda.gen.java.ParameterNameGenerator;
import de.jmda.gen.java.TypeNameGenerator;

public class DefaultParameterGenerator
		extends AbstractCompoundGenerator
		implements ParameterGenerator
{
	private AnnotationStatementsGenerator annotationStatementsGenerator;
	private TypeNameGenerator typeNameGenerator;
	private ParameterNameGenerator parameterNameGenerator;

	/**
	 * Sets component separator for component generation process to <code>" "
	 * </code>.
	 */
	public DefaultParameterGenerator()
  {
	  this(
	  		new DefaultAnnotationStatementsGenerator(),
	  		new DefaultTypeNameGenerator(),
	  		new DefaultParameterNameGenerator());
  }
	
	public DefaultParameterGenerator(
			String parameterTypeName, String parameterName)
	{
		this(
				new DefaultAnnotationStatementsGenerator(),
				new DefaultTypeNameGenerator(parameterTypeName),
				new DefaultParameterNameGenerator(parameterName));
	}

	public DefaultParameterGenerator(
      AnnotationStatementsGenerator annotationStatementsGenerator,
      TypeNameGenerator typeNameGenerator,
      ParameterNameGenerator parameterNameGenerator)
  {
	  super();

	  this.annotationStatementsGenerator = annotationStatementsGenerator;
	  this.typeNameGenerator = typeNameGenerator;
	  this.parameterNameGenerator = parameterNameGenerator;

	  setComponentSeparator(" ");
  }

	/**
	 * Returns collection of <code>Generator</code>s with the return values of the
	 * following methods in the following order:
	 * <ul>
	 *   <li>{@link #getAnnotationStatementsGenerator()}</li>
	 *   <li>{@link #getTypeNameGenerator()}</li>
	 *   <li>{@link #getParameterNameGenerator()}</li>
	 * </ul>
	 * 
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
	public List<Generator> getGeneratorComponents()
	{
		List<Generator> result = new LinkedList<Generator>();
		
		result.add(getAnnotationStatementsGenerator());
		result.add(getTypeNameGenerator());
		result.add(getParameterNameGenerator());

		return result;
	}

	@Override
	public AnnotationStatementsGenerator getAnnotationStatementsGenerator()
	{
		return annotationStatementsGenerator;
	}

	@Override
  public void setAnnotationStatementsGenerator(
      AnnotationStatementsGenerator generator)
  {
		if (generator == null)
		{
			return;
		}
		
		annotationStatementsGenerator = generator;
  }

	@Override
  public TypeNameGenerator getTypeNameGenerator()
  {
		return typeNameGenerator;
  }

	@Override
  public void setTypeNameGenerator(TypeNameGenerator generator)
  {
		if (generator == null)
		{
			return;
		}
		
		typeNameGenerator = generator;
  }

	@Override
  public ParameterNameGenerator getParameterNameGenerator()
  {
		if (parameterNameGenerator == null)
		{
			parameterNameGenerator = new DefaultParameterNameGenerator();
		}

		return parameterNameGenerator;
  }

	@Override
  public void setParameterNameGenerator(ParameterNameGenerator generator)
  {
		if (generator == null)
		{
			return;
		}
		
		parameterNameGenerator = generator;
  }
}